﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using VisionCloud.Core.Model.Ms;
using VisionCloud.Domain.Extension;
using VisionCloud.Domain.Repository.Interface.Ms;

namespace VisionCloud.Domain.Repository.Implement.Ms
{
    public class ProjectProgressViewRepository : BaseRepository<ProjectProgressView>, IProjectProgressViewRepository
    {
        public IQueryable<ProjectProgressView> SelectProgressList(List<Guid> projectIds, List<int> taskTypes)
        {
            var query = Db.Set<ProjectProgressView>().Where(x => projectIds.Contains(x.ProjectId))
                                                     .WhereIf(taskTypes?.Count > 0, x => taskTypes.Contains(x.TaskType));

            return query;
        }

        public async Task<List<ProjectProgressView>> GetProgressInfos(Guid projectId, string buildName, int taskType)
        {
            return await WhereAsync(x => x.ProjectId == projectId && x.BuildingName == buildName && taskType == x.TaskType);
        }
    }
}